﻿// Decompiled with JetBrains decompiler
// Type: LayersParser.Objects.Param
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;


namespace LayersParser.Objects;

public class Param : Common
{
  private bool _command;
  private string _defaultvalue;
  private string _type;
  private List<string> _choices = new List<string>();
  private string _min;
  private string _max;
  private string _maxlength;
  private string txValidatorType;
  private List<string> txTypes = new List<string>();
  private string _showList;
  private List<string> _signalType = new List<string>();
  private string linkTo;
  private string newValue;

  public Param()
  {
    this.Node = new XElement((XName) nameof (Param), (object) new XAttribute((XName) "Name", (object) ""));
  }

  public Param(XElement param)
  {
    this.Node = param;
    this.Name = (string) param?.Attribute((XName) "Name");
    this._max = (string) this.Node?.Attribute((XName) "MaxVal");
    this._min = (string) this.Node?.Attribute((XName) "MinVal");
    XElement node = this.Node;
    List<XElement> xelementList;
    if (node == null)
    {
      xelementList = (List<XElement>) null;
    }
    else
    {
      XElement xelement = node.Element((XName) "ComboDef");
      if (xelement == null)
      {
        xelementList = (List<XElement>) null;
      }
      else
      {
        IEnumerable<XElement> source = xelement.Elements((XName) "ElmDef");
        xelementList = source != null ? source.ToList<XElement>() : (List<XElement>) null;
      }
    }
    if (xelementList != null)
    {
      foreach (XElement xelement in this.Node.Element((XName) "ComboDef").Elements((XName) "ElmDef").ToList<XElement>())
        this._choices.Add(xelement.Value);
    }
    this._defaultvalue = (string) this.Node?.Attribute((XName) "Default");
    this._type = (string) this.Node?.Attribute((XName) "ValueType");
  }

  public string NewValue
  {
    get => this.newValue;
    set => this.newValue = value;
  }

  public string LinkTo
  {
    get => this.linkTo;
    set
    {
      this.linkTo = value;
      this.Node?.Element((XName) "ComboDef")?.Remove();
      this.Node.Add((object) new XElement((XName) "ComboDef", (object) new XAttribute((XName) nameof (LinkTo), (object) this.linkTo)));
    }
  }

  public List<string> SignalType
  {
    get => this._signalType;
    set => this._signalType = value;
  }

  public string ShowList
  {
    get => this._showList;
    set
    {
      this._showList = value;
      this.AddingShowList((object) value, nameof (ShowList));
    }
  }

  public List<string> TxTypes
  {
    get => this.txTypes;
    set
    {
      this.txTypes = value;
      this.AddingChoices(this.txTypes, "PickTypes", "PickType");
    }
  }

  public string TxValidatorType
  {
    get => this.txValidatorType;
    set
    {
      this.txValidatorType = value;
      this.AddingAttribute((object) this.txValidatorType, nameof (TxValidatorType));
    }
  }

  public string MaxBound
  {
    get => this._max;
    set
    {
      this._max = value;
      this.AddingAttribute((object) this._max, "MaxVal");
    }
  }

  public string MinBound
  {
    get => this._min;
    set
    {
      this._min = value;
      this.AddingAttribute((object) this._min, "MinVal");
    }
  }

  public string MaxLength
  {
    get => this._maxlength;
    set
    {
      this._maxlength = value;
      this.AddingAttribute((object) this._maxlength, "MaxLenght");
    }
  }

  public List<string> Choices
  {
    get => this._choices;
    set
    {
      this._choices = value;
      this.AddingChoices(this._choices, "ComboDef", "ElmDef");
    }
  }

  public bool Command
  {
    get => this._command;
    set => this._command = value;
  }

  public string DefaultValue
  {
    get => this._defaultvalue;
    set
    {
      this._defaultvalue = value;
      this.AddingAttribute((object) this._defaultvalue, "Default");
    }
  }

  public string Type
  {
    get => this._type;
    set
    {
      this._type = value;
      this.AddingAttribute((object) this._type, "ValueType");
    }
  }

  private void AddingAttribute(object data, string attribute)
  {
    this.Node?.Attribute((XName) attribute)?.Remove();
    if (data == null)
      return;
    this.Node.Add((object) new XAttribute((XName) attribute, data));
  }

  private void AddingShowList(object data, string attribute)
  {
    this.Node?.Element((XName) "PickTypes")?.Add((object) new XAttribute((XName) attribute, (object) data.ToString()));
  }

  private void AddingChoices(List<string> choices, string firstname, string secondname)
  {
    this.Node?.Element((XName) firstname)?.Remove();
    if (choices.Count <= 0)
      return;
    this.Node.Add((object) new XElement((XName) firstname));
    if (firstname == "ComboDef")
      this.Node.Element((XName) firstname).Add((object) new XElement((XName) secondname, (object) ""));
    foreach (string choice in choices)
      this.Node.Element((XName) firstname).Add((object) new XElement((XName) secondname, (object) choice));
  }
}
